package com.qk.controller;

import com.qk.aop.anno.LogRecord;
import com.qk.common.Result;
import com.qk.dto.activity.ActivityDTO;
import com.qk.entity.Activity;
import com.qk.service.ActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: zhangchuang
 * @Date: 2025/10/13 14:51
 * @Description: 活动控制器
 */
@RestController
@RequestMapping("/activities")
@Slf4j
@SuppressWarnings("all")
public class ActivityController {

    @Autowired
    private ActivityService activityService;

    @GetMapping("/type/{type}")
    public Result getByType(@PathVariable Integer type) {
        log.info("获取活动列表，参数：{}", type);
        return Result.success(activityService.getByType(type));
    }

    @LogRecord
    @PutMapping()
    public Result update(@RequestBody Activity activity) {
        log.info("修改活动，参数：{}", activity);
        return activityService.updateActivityById(activity) ? Result.success() : Result.error();
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id) {
        log.info("查询活动，参数：{}", id);
        return Result.success(activityService.getById(id));
    }

    @LogRecord
    @PostMapping
    public Result save(@RequestBody Activity activity) {
        log.info("保存活动，参数：{}", activity);
        return activityService.addActivity(activity) ? Result.success() : Result.error();
    }

    @LogRecord
    @DeleteMapping("/{id}")
    public Result deleteActivityById(@PathVariable Integer id) {
        log.info("删除活动，参数：{}", id);
        return activityService.deleteActivityById(id) ? Result.success() : Result.error();
    }

    @GetMapping()
    public Result list(ActivityDTO activityDTO) {
        log.info("获取活动列表，参数：{}", activityDTO);
        return Result.success(activityService.getActivityByPage(activityDTO));
    }

}
